// 游戏对象类
// 基类

#ifndef ALICE_OBJECT_GAME_OBJECT_H_
#define ALICE_OBJECT_GAME_OBJECT_H_

#include <cstring>

#include <SDL.h>

#include "object.h"
#include "transform.h"
#include "point.h"

namespace alice {

struct Properties {
  public:
    Properties(std::string texture_id, double x, double y, int w, int h, SDL_RendererFlip flip=SDL_FLIP_NONE) {
      this->texture_id = texture_id;
      this->X = x;
      this->Y = y;
      this->width = w;
      this->height = h;
      this->flip = flip;
    }

  public:
    std::string texture_id;
    int width, height;
    double X, Y;
    SDL_RendererFlip flip;
};

class GameObject : public Object {
  public:
    GameObject(Properties* props):texture_id_(props->texture_id),
      width_(props->width), height_(props->height), flip_(props->flip) {

      transform_ = new Transform(props->X, props->Y);
      double px = props->X + props->width / 2;
      double py = props->Y + props->height / 2;
      origin_ = new Point(px, py);
    }
    
    virtual ~GameObject() {
      delete transform_;
      delete origin_;
    }

    virtual void Draw()=0;
    virtual void Clean()=0;
    virtual void Update(double delta_time)=0;
    Point* GetOrigin() { return origin_; }

  protected:
    std::string texture_id_;
    int width_, height_;
    Transform* transform_;
    SDL_RendererFlip flip_;
    Point* origin_; // 图片的原点, 即中点
};

}

#endif // ALICE_OBJECT_GAME_OBJECT_H_

